package models;

import java.util.*;

import javax.persistence.*;

import play.db.jpa.*;

public class Board{
	
	private static final int ROW_NUMBER = 8;
	private static final int COLUMN_NUMBER = 8;
	private static final int ITEM_NUMBER = 6;
	
	public boolean status = false;
    public int[][] itemList;
    public boolean[][] tmpItemList;
    public int[] finishItems;
    
    public Board() {
    	itemList = createRandomData();
    }
    
    private static int[][] createRandomData(){
		
		int itemList[][] = new int[8][8];
		
		  for (int i = 0 ; i < ROW_NUMBER ; i++) 
		  {
			  for (int j = 0 ; j < COLUMN_NUMBER ; j++) 
			  {
				  int randomValue = randomInt(1, ITEM_NUMBER);

				  if (i > 1) {
					  while(itemList[i-2][j] == randomValue && itemList[i-1][j] == randomValue){
						  randomValue = randomInt(1, ITEM_NUMBER);
					  }
				  }
				  
				  if (j > 1) {
					  while(itemList[i][j-2] == randomValue && itemList[i][j-1] == randomValue){
						  randomValue = randomInt(1, ITEM_NUMBER);

						  if (i > 1) {
							  while(itemList[i-2][j] == randomValue && itemList[i-1][j] == randomValue){
								  randomValue = randomInt(1, ITEM_NUMBER);
							  }
						  }

					  }
				  }

				  itemList[i][j] = randomValue;
			  }
		  }  		  		 
			  
		  return itemList;
	}
    
    public static int randomInt(int min, int max){
		int result = min;
		
		Random random = new Random();
		
		result = random.nextInt(max) + min;
		
		return result;
	}
}
